<template>
  <div class="company">
    <!-- 公司 -->
    <el-input
      placeholder="请输入部门名称"
      prefix-icon="el-icon-search"
      v-model="filterText"
    >
    </el-input>
    <!-- 树形控件 -->
    <el-tree
      class="filter-tree"
      :data="treeData"
      :props="defaultProps"
      default-expand-all
      :filter-node-method="filterNode"
      ref="tree"
    >
    </el-tree>
  </div>
</template>
<script>
export default {
  data() {
    return {
      filterText: '',
      treeData: [
        {
          id: 1,
          label: "若依科技",
          children: [
            {
              id: 2,
              label: "深圳总公司",
              children: [
                {
                  id: 4,
                  label: "研发部门"
                },
                {
                  id: 5,
                  label: "市场部门"
                },
                {
                  id: 6,
                  label: "测试部门"
                },
                {
                  id: 7,
                  label: "财务部门"
                },
                {
                  id: 8,
                  label: "运维部门"
                }
              ]
            },
            {
              id: 3,
              label: "长沙分公司",
              children: [
                {
                  id: 9,
                  label: "市场部门"
                },
                {
                  id: 10,
                  label: "财务部门"
                }
              ]
            }
          ]
        }
      ],
      defaultProps: {
        children: "children",
        label: "label"
      }
    };
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    }
  },

  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    }
  }
};
</script>
<style lang="scss">
.company {
  margin: 20px;
  height: 100%;
  input {
      margin-bottom: 20px;
  }
}
</style>
